//
//  HEMyOrderInfoCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/11/6.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEMyOrderInfoCell.h"

@interface HEMyOrderInfoCell ()

@property (nonatomic, strong) UILabel *titleLb;

@property (nonatomic, strong) UILabel *contentLb;
@property (nonatomic, strong) QMUIButton *check;

@end

@implementation HEMyOrderInfoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
     if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
         self.selectionStyle = UITableViewCellSelectionStyleNone;
         [self initUI];
     }
     return self;;
}

- (void)initUI {
    
    _titleLb = [UILabel new];
    _contentLb.font = DYFont(15);
    _titleLb.text = @"订单编号：";
    _titleLb.textColor = CNavDargGrayColor;
    [self.contentView addSubview:_titleLb];
    
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(5);
        make.left.equalTo(self.contentView).mas_offset(15);
        make.width.mas_offset([_titleLb.text widthForFont:DYFont(15)] + 15);
    }];
    [_titleLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
    
    _contentLb = [UILabel new];
    _contentLb.font = DYFont(15);
    _contentLb.textColor = CNavDargGrayColor;
    _contentLb.text = @"-";
    _contentLb.numberOfLines = 0;
     [self.contentView addSubview:_contentLb];
    _contentLb.textAlignment = NSTextAlignmentLeft;
    [_contentLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(5);
        make.left.equalTo(_titleLb.mas_right).mas_offset(0);
        make.right.equalTo(self.contentView).mas_offset(-70);
        make.bottom.equalTo(self.contentView).mas_offset(-5);
    }];
//    _contentLb.preferredMaxLayoutWidth = KScreenWidth - 90 - 30 - 20 - 70;

    QMUIButton *check = [[QMUIButton alloc] init];
    _check = check;
    check.tintColorAdjustsTitleAndImage = KHexColor(@"FFA900");
    check.adjustsImageTintColorAutomatically = NO;
    check.spacingBetweenImageAndTitle = 10;
    [check setTitle:@"复制" forState:UIControlStateNormal];
    check.titleLabel.font = DYFont(15);
    [self.contentView addSubview:check];
    [check addTarget:self action:@selector(copyClick) forControlEvents:UIControlEventTouchUpInside];
    
    [check mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_titleLb);
        make.right.equalTo(self.contentView).mas_offset(-10);
    }];
}

- (void)copyClick {
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = _contentLb.text;
    [Dialog toastBottom:@"复制成功"];
}

- (void)refreshContent:(GDFiterCellModel *)fiterModel formModel:(GDFormModel *)formModel indexPath:(NSIndexPath *)indexPath {
    NSInteger a = indexPath.row-1;
    NSDictionary *model = (NSDictionary *)formModel.od_orderInfoItems[a];
 
    _titleLb.text = model[@"name"];
    _contentLb.text = model[@"value"];
        
    if (a == 0) {
        _check.hidden = NO;
        [_contentLb mas_updateConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).mas_offset(-70);
        }];
    }else{
        _check.hidden = YES;
        
        [_contentLb mas_updateConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).mas_offset(-30);
        }];
    }
    
    if (a == (formModel.od_orderInfoItems.count-1)) {
        [_contentLb mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.contentView).mas_offset(-15);
        }];
    }else {
        [_contentLb mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.contentView).mas_offset(-5);
        }];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
